#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3005;

int n, m;
int h[N];
int dp[N][N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> h[i];

  int mx = 1;
  rep(i, 1, n) {
    rep(d, 1, n - 1) dp[i][d] = 1;
    per(j, i - 1, 1) {
      if (h[i] != h[j]) continue;
      int d = i - j;
      dp[i][d] = 1 + dp[j][d];
      mx = max(mx, dp[i][d]);
    }
  }
  cout << mx;
  return 0;
}